﻿using KKU.RBSFPP.Shared.ReportQuery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KKU.RBSFPP.Web.Administrator.ReportingPages.Prediction
{
    public partial class PredicPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var now = DateTime.Today;
            var previous = now.AddMonths(-1);
            
            #region ปัจจัยที่เกี่ยวข้อง

            // เงินบาท
            
            var currentBath = ReportQuery.GetFactorValues(1, now.Year, now.Month);
            var previousBath = ReportQuery.GetFactorValues(1, previous.Year, previous.Month);
            int bath = 0;
            if (currentBath > previousBath)
            {
                // ขึ้น
                Image1.ImageUrl = "~/Images/Up.png";
                bath = 1;
            }
            else if (currentBath < previousBath)
            {
                // ลง
                Image1.ImageUrl = "~/Images/Down.png";
                bath = 0;
            }
            else
            {
                // ไม่เปลี่ยนแปลง
                Image1.ImageUrl = "~/Images/None.png";
                bath = -1;
            }
            
            // ดอกเบี้ย
            var currentRate = ReportQuery.GetFactorValues(2, now.Year, now.Month);
            var previousRate = ReportQuery.GetFactorValues(2, previous.Year, previous.Month);
            if (currentRate > previousRate)
            {
                // ขึ้น
                Image2.ImageUrl = "~/Images/Up.png";
            }
            else if (currentRate < previousRate)
            {
                // ลง
                Image2.ImageUrl = "~/Images/Down.png";
            }
            else
            {
                // ไม่เปลี่ยนแปลง
                Image2.ImageUrl = "~/Images/None.png";
            }

            // ทองคำ
            var currentGold = ReportQuery.GetFactorValues(3, now.Year, now.Month);
            var previousGold = ReportQuery.GetFactorValues(3, previous.Year, previous.Month);
            if (currentGold > previousGold)
            {
                // ขึ้น
                Image3.ImageUrl = "~/Images/Up.png";
            }
            else if (currentGold < previousGold)
            {
                // ลง
                Image3.ImageUrl = "~/Images/Down.png";
            }
            else
            {
                // ไม่เปลี่ยนแปลง
                Image3.ImageUrl = "~/Images/None.png";
            }

            // น้ำมัน
            var currentOil = ReportQuery.GetFactorValues(4, now.Year, now.Month);
            var previousOil = ReportQuery.GetFactorValues(4, previous.Year, previous.Month);
            int oil = 0;
            if (currentOil > previousOil)
            {
                // ขึ้น
                Image4.ImageUrl = "~/Images/Up.png";
                oil = 1;
            }
            else if (currentOil < previousOil)
            {
                // ลง
                Image4.ImageUrl = "~/Images/Down.png";
                oil = 0;
            }
            else
            {
                // ไม่เปลี่ยนแปลง
                Image4.ImageUrl = "~/Images/None.png";
                oil = -1;
            }

            
            //สูตรการทำนายราคาขาย

            if (bath == 1 & oil == 1)
            {
               Label1.Text = "ราคาขายลง";
            }
            else if (bath == 1 & oil == 0)
            {
                Label1.Text = "ราคาขายลง";
            }
            else if (bath == 1 & oil == -1)
            {
                Label1.Text = "ราคาขายขึ้น";
            }
            else if (oil == -1)
            {
                Label1.Text = "ราคาของขึ้น";
            }
            else
            {
                Label1.Text = "ไม่สามารถทำนายได้";
            }
            

            #endregion ปัจจัยที่เกี่ยวข้อง

            #region หมวดหมู่

            // พลาสติก
            var currentPlastic = ReportQuery.GetProductPricing(1, now.Year, now.Month);
            var previousPlastic = ReportQuery.GetProductPricing(1, previous.Year, previous.Month);
            if (currentPlastic > previousPlastic)
            {
                // ขึ้น
                Image5.ImageUrl = "~/Images/Up.png";
            }
            else if (currentPlastic < previousPlastic)
            {
                // ลง
                Image5.ImageUrl = "~/Images/Down.png";
            }
            else
            {
                // ไม่เปลี่ยนแปลง
                Image5.ImageUrl = "~/Images/None.png";
            }

            // เหล็ก
            var currentSteel = ReportQuery.GetProductPricing(2, now.Year, now.Month);
            var previousSteel = ReportQuery.GetProductPricing(2, previous.Year, previous.Month);
            if (currentSteel > previousSteel)
            {
                // ขึ้น
                Image6.ImageUrl = "~/Images/Up.png";
            }
            else if (currentSteel < previousSteel)
            {
                // ลง
                Image6.ImageUrl = "~/Images/Down.png";
            }
            else
            {
                // ไม่เปลี่ยนแปลง
                Image6.ImageUrl = "~/Images/None.png";
            }

            // กระดาษ
            var currentPaper = ReportQuery.GetProductPricing(3, now.Year, now.Month);
            var previousPaper = ReportQuery.GetProductPricing(3, previous.Year, previous.Month);
            if (currentPaper > previousPaper)
            {
                // ขึ้น
                Image7.ImageUrl = "~/Images/Up.png";
            }
            else if (currentPaper < previousPaper)
            {
                // ลง
                Image7.ImageUrl = "~/Images/Down.png";
            }
            else
            {
                // ไม่เปลี่ยนแปลง
                Image7.ImageUrl = "~/Images/None.png";
            }

            #endregion หมวดหมู่
        }
    }
}